package com.linx.rxlife

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import io.reactivex.disposables.Disposable

abstract class RxLife(
    owner: LifecycleOwner,
    atLeastState: Lifecycle.State
) : Life(owner, atLeastState), Disposable {

    protected var disposable: Disposable? = null

    final override fun onInactive() {
        disposable?.dispose()
    }

    override fun isDisposed(): Boolean {
        return disposable?.isDisposed ?: true
    }

    override fun dispose() {
        onInactive()
    }
}